<template>
  <div class="app-container">
    <div class="filter-container">
      <p style="float:left;margin-top:5px;margin-left:2%">商户手机号：</p>
      <el-input
        v-model="listQuery.userName"
        size="small"
        placeholder="请输入手机号"
        style="width: 200px;float:left"
        class="filter-item"
      />
      <p style="display:inline-block;margin-left:2%">类型：</p>
      <el-select v-model="listQuery.shopType" size="small" placeholder="全部" clearable class="filter-item" style="width: 130px">
        <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
      </el-select>
      <p style="float:left;margin-top:5px;margin-left:2%">地址：</p>
      <v-distpicker
        style="float:left;margin-top:-5px"
        :province="listQuery.province"
        :city="listQuery.city"
        :area="listQuery.county"
        @selected="searchSelect"
        />
      <el-button
        size="small"
        class="filter-item"
        type="success"
        icon="el-icon-search"
        style="margin-left:3%"
        @click="handleFilter"
      >
        搜索
      </el-button>
    </div>

    <el-table
      :key="tableKey"
      :data="list"
      size="small"
      border
      fit
      highlight-current-row
      style="width: 100%;margin-top:1%"
    >
    <el-table-column type="index">
    </el-table-column>
    <el-table-column label="商户手机号" width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.userName }}</span>
          <!-- <img :src="scope.row.imgUri" style="width:300px;height:200px" alt=""> -->
        </template>
      </el-table-column>
      <el-table-column label="身份证号" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.idCard }}</span>
        </template>
      </el-table-column>
      <el-table-column label="省" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.province }}</span>
        </template>
      </el-table-column>
      <el-table-column label="市" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.city }}</span>
        </template>
      </el-table-column>
      <el-table-column label="区/县" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.county }}</span>
        </template>
      </el-table-column>
      <el-table-column label="乡/镇" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.town }}</span>
        </template>
      </el-table-column>
      <el-table-column label="详细地址" width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付宝号" width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.alipayAcount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.shopType=='ONE_PERSON'?'个人商户':'企业商户' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="营业执照" width="200px" align="center">
        <template slot-scope="scope">
          <img height="150px" @click="showBig(scope.row)" :src="scope.row.businessPhoto" alt="">
        </template>
      </el-table-column>
      <el-table-column
        label="电子协议"
        align="center"
        width="100px"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button
            size="small"
            align="center"
            type="primary"
            @click="handleUpdate(row)"
          >
            查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
    <el-dialog :visible.sync="dialogible" append-to-body>
        <img :src="dialogImage" width="100%" alt >
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible" append-to-body :close-on-click-modal="false">
        <img :src="checkImage" width="100%" alt >
    </el-dialog>
  </div>
</template>

<script>
// 异步请求 delLly
import { getListPage,examine} from '@/api/businessList/index'
import Vue from 'vue'
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // 分页插件

const calendarTypeOptions = [
  { key: 'ONE_PERSON', display_name: '个人商户' },
  { key: 'BUSINESS', display_name: '企业商户' },
]
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

export default {
  inject:["reload"],
  components: { Pagination },
  filters: {
    typeFilter(type) {
      return calendarTypeKeyValue[type]
    },
  },
  data() {
    return {
      deptValue:'',
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        pageNum: 1,
        pageSize: 10,
        provinceCode: '',
        cityCode: '',
        countyCode: '',
        province: '',
        city: '',
        county: '',
        shopType:'',
        userName:''
      },
      dialogible: false,
      temp: {},
      checkImage:'',
      dialogFormVisible: false,
      calendarTypeOptions,
      dialogImage: '',
    }
  },
  created() {
    this.getList()
  },
  methods: {
    //点击放大营业执照
    showBig(row) {
      // console.log(row)
      this.dialogible = true
      this.dialogImage = row.businessPhoto
    },
    //省市县搜索
    searchSelect:function(data){
        if(data.province.code===undefined){
            this.listQuery.provinceCode=''
        }else{
            this.listQuery.provinceCode = data.province.code+'000000'
        }
        if(data.city.code===undefined){
            this.listQuery.cityCode=''
        }else{
            this.listQuery.cityCode = data.city.code+'000000'
        }
        if(data.area.code===undefined){
            this.listQuery.countyCode=''
        }else{
            this.listQuery.countyCode = data.area.code+'000000'
        }
    },
    //表格数据
    getList() {
      this.listLoading = true
      var params = {
        // pageConvert: true,
        pageNum: this.listQuery.pageNum-1,
        pageSize: this.listQuery.pageSize,
        provinceCode:this.listQuery.provinceCode,
        cityCode:this.listQuery.cityCode,
        countyCode:this.listQuery.countyCode,
        userName:this.listQuery.userName,
        shopType:this.listQuery.shopType,
      }
      getListPage(params).then(response => {
        this.list = response.content
        this.total = response.totalElements
        // Just to simulate the time of the request
      })
    },
    //搜索
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    //查看
     handleUpdate(row) {
      this.dialogFormVisible = true
      var proId=row.id
      examine(proId).then(res=>{
        this.checkImage=res.data
      })
    },
  }
}
</script>
<style scoped>

</style>